import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { User } from '../../model/User';
import { PageInfo } from '../../model/Page';
import { UserService } from '../../service/user.service';

@Component({ 
    templateUrl: 'user.component.html',
})
export class UserComponent implements OnInit {



      page: PageInfo;
      users: User[];
      private deleteId=0;

      constructor(private router:Router,private  _userService:UserService) { }

      ngOnInit(): void {
          this.getAllUser();
      }

      getAllUser(): void {
            this._userService
                .getAllUser()
                .then(page =>{
                    this.page = page;
                    this.users=this.page.list;
                } );
               console.log(this.users);
     }

    

     updateDeleteId(id:number){

         this.deleteId=0   
         this.deleteId=id;
        
          
     }

     deleteUser(){

        
         this._userService.deleteUser(this.deleteId).then(data=>{
           this.deleteId=0;
           this.getAllUser();
           
         });
      

     }

     updataUser(id):void{

         this.router.navigate(['user/edit',id]);


         alert(id);
     }

}
